<template>
  <div class="mr-pr-topTable">
    <div class="el-mr-mr-midSearch">
      <ul>
        <li>
          <span>图号</span>
        </li>
        <li class="wewewe">
          <el-input
            size="mini"
            v-model="searchInfo.itemCode"
            placeholder="请输入内容"
          ></el-input>
        </li>
        <li>
          <span>质量编号</span>
        </li>
        <li>
          <el-input
            size="mini"
            v-model="searchInfo.qualityCode"
            placeholder="请输入内容"
          ></el-input>
        </li>
        <li>
          <el-button size="mini" type="primary" @click="scanningSearch">查询</el-button>
          <el-button size="mini" type="primary" @click="inputRemark">录入备注信息</el-button>
        </li>
      </ul>
    </div>
    <!--录入备注信息-->
    <el-dialog
      :visible.sync="dialogVisible"
      width="30%">
      <el-form ref="form" :model="form" label-width="80px">
        <el-form-item label="备注">
          <el-input type="textarea" v-model="form.remark"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button size="mini" @click="dialogVisible = false">取 消</el-button>
        <el-button size="mini" type="primary" @click="saveRemark">确 定</el-button>
      </span>
    </el-dialog>

    <div class="mr-pr-firstTable">
      <el-table
      size="mini"
      :data="resData"
      style="width: 100%"
      height="258"
      @selection-change="handleSelectionChange"
      highlight-current-row
      :cell-style="cellStyle"
    >
    <el-table-column type="selection" width="40"> </el-table-column>
      <el-table-column type="index" label="序号" width="50"  :show-overflow-tooltip="true"> </el-table-column>
      <el-table-column prop="barcode" label="条码"  :show-overflow-tooltip="true"> </el-table-column>
      <el-table-column prop="isPaper" label="是否带证"  :show-overflow-tooltip="true"> </el-table-column>
      <el-table-column prop="requireShop" label="接收单位" :show-overflow-tooltip="true"> </el-table-column>

      <el-table-column prop="itemCode" label="零件图号" width="170" :show-overflow-tooltip="true"> </el-table-column>
      <el-table-column prop="qualityCode" label="质量编号" width="150" :show-overflow-tooltip="true"> </el-table-column>
      <el-table-column prop="substituteCode" label="限用架次" width="170" :show-overflow-tooltip="true"> </el-table-column>
      <el-table-column prop="maxStorageDate" label="最长保管期" width="170" :show-overflow-tooltip="true"> </el-table-column>
      <el-table-column prop="requireShop" label="需求单位" width="170" :show-overflow-tooltip="true"> </el-table-column>
      <el-table-column prop="itemType" label="物料大类" :show-overflow-tooltip="true"> </el-table-column>
      <el-table-column prop="itemName" label="物料名称" width="110" :show-overflow-tooltip="true"> </el-table-column>
      <el-table-column prop="isCoor" label="协调单状态" width="100" :show-overflow-tooltip="true"> </el-table-column>
      <el-table-column prop="productCode" label="机型" :show-overflow-tooltip="true"> </el-table-column>
      <el-table-column prop="batchNo" label="批次" :show-overflow-tooltip="true"> </el-table-column>
      <el-table-column prop="startLotNo" label="起始架次"  :show-overflow-tooltip="true"> </el-table-column>
      <el-table-column prop="endLotNo" label="截止架次"  :show-overflow-tooltip="true"> </el-table-column>
      <el-table-column prop="receiveRemark" label="备注" :show-overflow-tooltip="true"> </el-table-column>
      <el-table-column prop="deliveryQty" label="数量" :show-overflow-tooltip="true"> </el-table-column>
      <el-table-column prop="mdsUnit" label="计量单位" :show-overflow-tooltip="true"> </el-table-column>
      <el-table-column prop="empName" label="移交人" :show-overflow-tooltip="true"> </el-table-column>
      <el-table-column prop="deliveryDate" label="移交时间" width="150" :show-overflow-tooltip="true"> </el-table-column>
      
    </el-table>
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="pageNumber"
      :page-sizes="[100,600]"
      :page-size="pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="totalCount">
    </el-pagination>
    </div>
  </div>
</template>
<script>
import { mrMhAll,saveRemark } from "@/utils/api.js";
import request from "../../../../../utils/request";

export default {
  name: "PrTables",
  data() {
    return {
      //
      isIndex: true,
      // 表页一表一
      // 表一数据总数
      totalCount: 0,
      // 表一每页数据个数
      pageSize: 100,
      // 当前页数
      pageNumber: 1,
      resData: [],
      tableDtata: [],
      searchInfo:{
        itemCode:"",
        qualityCode:"",
        mProductNumber:""
      },
      selectedData:[],
      dialogVisible: false,
      form:{
        remark:""
      }
    };
  },
  methods: {
    
    // 选择每页条数后请求接口更新表格
    handleSizeChange(val) {
      this.pageSize = val
      mrMhAll({
        funcType:"part",
        pageParameter: {
          rows: this.pageSize,
          page: this.pageNumber,
        },
      }).then((res) => {
        this.resData = res.data.responseBody.result;
        this.totalCount = res.data.responseBody.pageParameter.totalCount;
        this.$options.methods.cellStyle.bind(this)();
      });
      // 传pageSize，pageNumber给midSearch
      this.$bus.$emit('prPageNumbers',{pageSize:this.pageSize,pageNumber:this.pageNumber})
      // console.log(`每页 ${val} 条`);
    },
    // 分页函数
    handleCurrentChange(val) {
      this.pageNumber = val;
        mrMhAll({
          funcType:"part",
          pageParameter: {
            rows: this.pageSize,
            page: this.pageNumber,
          },
      }).then((res) => {
        this.resData = res.data.responseBody.result;
        this.totalCount = res.data.responseBody.pageParameter.totalCount;
        this.$options.methods.cellStyle.bind(this)()
      });
    },
    // 好像这个函数没有用 暂时未删除
    myclass(val){
      // console.log(val)
      if(val.row.isCoor == '协调中' && val.row.isCoor == '申请归零'){
        return 'background-color:red'
      }
    },
    cellStyle(val){
      // console.log(val.row.isCoor)
      if(typeof(val)=="undefined"){
        return ;
      }
      if(val.row.isCoor == '协调中' || val.row.isCoor == '申请归零'){
        return 'background-color:red'
      }
    },
    reloadTable(){
      var that = this;
      mrMhAll({
        funcType:"part",
        pageParameter: {
          rows: this.pageSize,
          page: this.pageNumber
        },
        searchParams:this.searchInfo
      }).then((res) => {
        console.log('成品接收表1111',res)
        that.resData = res.data.responseBody.result;
        that.totalCount = res.data.responseBody.pageParameter.totalCount;
        that.$options.methods.cellStyle.bind(that)()
      })
    },
    scanningSearch(){
      this.$options.methods.reloadTable.bind(this)();
    },
    handleSelectionChange(val){
      this.selectedData = val;
      console.log("this.selectedData",this.selectedData);
    },
    //录入备注
    inputRemark(){
      if(this.selectedData.length==0){
        this.$Alert({title: "失败",message: "请至少选择一条记录",type: "error"})
        return ;
      }
      //循环遍历图号，存在不同的提示错误
      if(this.selectedData.length>1){
        let j = 0;
        for(let i=0;i<this.selectedData.length;i++){
          let item = this.selectedData[0].itemCode;
          let itemCodes = this.selectedData[i].itemCode;
          if(item!=itemCodes){
            j++;
          }
        }
        if(j>0){
          this.$Alert({title: "失败",message: "请选择相同的图号进行备注",type: "error"})
          return;
        }
        
      }
      this.dialogVisible = true;
      request.post("/WmsDeliverPlan/setDefaultNotes",{"itemCode":this.selectedData[0].itemCode}).then((res)=>{
        console.log("参数",res);
        this.form.remark = res.data.retMsg.pValue;
      })
    },
    saveRemark(){
      this.dialogVisible = false;
      saveRemark({
        dliverys:this.selectedData,
        remark:this.form.remark
      }).then((res)=>{
        console.log("res",res);
        if(res.data.retCode=="200"){
          this.$Alert({title: "成功",message: res.data.message,type: "success"})
        }else{
          this.$Alert({title: "失败",message: res.data.message,type: "error"})
        }
        this.$options.methods.reloadTable.bind(this)();
      });
    }
  },
  watch: {
  },
  mounted() {
    
    
    mrMhAll({
          funcType:"part",
          pageParameter: {
            rows: this.pageSize,
            page: this.pageNumber,
          },
      }).then((res) => {
        this.resData = res.data.responseBody.result;
        this.totalCount = res.data.responseBody.pageParameter.totalCount;
        this.$options.methods.cellStyle.bind(this)()
        this.$bus.$emit('partReceiveTopTable',this.resData)
      })
     this.$bus.$on('refreshPartTopTable',(e)=>{
      mrMhAll({
          funcType:"part",
          pageParameter: {
            rows: this.pageSize,
            page: this.pageNumber,
          },
      }).then((res) => {
        this.resData = res.data.responseBody.result;
        this.totalCount = res.data.responseBody.pageParameter.totalCount;
        this.$options.methods.cellStyle.bind(this)()
        this.$bus.$emit('partReceiveTopTable',this.resData)
      })
     })
  }
};
</script>
<style scoped>
.mr-pr-topTable {
  width: 100%;
  height: 100%;
}
.mr-pr-firstTable {
  text-align: center;
}
.el-table--enable-row-hover .el-table_body tr:hover>td {
  background-color: red !important;
}
.el-mr-mr-midSearch ul li {
  height: 35px;
  float: left;
  margin-right: 10px;
  line-height: 35px;
}
</style>